<?php
if (!isset($rows) or !isset($rows[0]) or !isset($rows[0]['reach']) or $rows[0]['reach'] == 0) {
	$message = BUtils::T('special_report_not_ready_eg');
	echo <<<HTML
<div class="well well-large gray center">
	<div style="color:#cde;">
		<i class="icon-gears icon-4x"></i>
	</div>
	<div class="hr hr4"></div>
	<p>{$message}</p>
</div>
HTML;
} else {
	$reach_array = $clicks_array = $notifications_array = $spread_array = $redeems_array = array();
	$month_array = array();
	foreach ($rows as $r) {
		$month_array[] = $r['year'] . '.' . $r['month'];
		$clicks_array[] = (int)$r['clicks'];
		$notifications_array[] =(int) $r['notifications'];
		$spread_array[] = (int)$r['spread'];
		$redeems_array[] = (int)$r['redeems'];
		$reach_array[] = (int)$r['reach'];
	}
?>
<div class="row-fluid" style="position:relative;">
	<div id="chart-stats" class="span12" style="height:480px"></div>
	<div style="position:absolute;bottom:0;background:#fff;height:14px;width:30%;margin-left:70%;"></div>
</div>
<script type="text/javascript">
$(function() {
	$('#chart-stats').highcharts({
		chart: {
			type: 'column'
		},
		title: {
			text: ''
		},
		xAxis: {
			categories: <?php echo json_encode($month_array, true); ?>
		},
		yAxis: {
			min: 0,
			title: {
				text: '<?php echo BUtils::T('special_report_yaxis_lbl'); ?>'
			}
		},
		tooltip: {
			headerFormat: '<span style="font-size:10px">{point.key}:</span><table>',
			pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
				'<td style="padding:0"><b>{point.y}</b></td></tr>',
			footerFormat: '</table>',
			shared: true,
			useHTML: true
		},
		plotOptions: {
			column: {
				pointPadding: 0.2,
				borderWidth: 0
			}
		},
		series: [{
			name: '<?php echo BUtils::T('special_report_reach_lbl'); ?>',
			data: <?php echo json_encode($reach_array, true); ?>
		}, {
			name: '<?php echo BUtils::T('special_report_clicks_lbl'); ?>',
			data: <?php echo json_encode($clicks_array, true); ?>
		}, {
			name: '<?php echo BUtils::T('special_report_notifications_lbl'); ?>',
			data: <?php echo json_encode($notifications_array, true); ?>
		}, {
			name: '<?php echo BUtils::T('special_report_redeems_lbl'); ?>',
			data: <?php echo json_encode($redeems_array, true); ?>
		}]
	});
});
</script>
<?php } ?>